/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JP_RegistraAccion.java
 *
 * Created on Jul 15, 2009, 4:51:39 PM
 */

package gui;
import delegate.GestionDelegate;
import gui.tabbedpane.JP_DatosCliente;
import gui.tabbedpane.JP_Masivo;
import controlacciones.ejb3.entity.TbCliente;
import controlacciones.ejb3.entity.TbArea;
import controlacciones.ejb3.entity.TbTipoAccionClasificacionAccionArea;
import helper.JP_Utiles_PanelModelo;
import helper.JP_Utiles_PanelBotonesMantenimiento;
import helper.Utiles_MensajesDialogo;
import java.awt.BorderLayout;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jdesktop.application.Task;
import com.jidesoft.hints.ListDataIntelliHints;
import controlaccionescomercial.ControlAccionesComercialApp;
import java.util.Date;
import javax.swing.JInternalFrame;

/**
 *
 * @author Vanessa
 */
public class JP_RegistrarAccion1 extends JP_Utiles_PanelModelo {

    /** Creates new form JP_RegistraAccion */
    public JP_RegistrarAccion1() {
        inicializaComponentes();
    }

    private void inicializaComponentes(){
        initComponents();
        jp_dc = new JP_DatosCliente();
        jp_dc.setVentana( 1 );
        jp_DatosCliente.setLayout(new BorderLayout());
        jp_DatosCliente.add( jp_dc, BorderLayout.CENTER );

        //Datos Complementarios
        jp_ma = new JP_Masivo();
        jp_Masivo.setLayout(new BorderLayout());
        jp_Masivo.add( jp_ma, BorderLayout.CENTER );

        //Panel de Operaciones
        ArrayList alBotones = new ArrayList( 1 );
        alBotones.add( new Integer( JP_Utiles_PanelBotonesMantenimiento.BOTON_GUARDAR ) );
        alBotones.add( new Integer( JP_Utiles_PanelBotonesMantenimiento.BOTON_LIMPIAR ) );
        alBotones.add( new Integer( JP_Utiles_PanelBotonesMantenimiento.BOTON_CERRAR ) );

        jp_ope = new JP_Utiles_PanelBotonesMantenimiento( this, alBotones );
        jp_Operaciones.setLayout( new BorderLayout() );
        jp_Operaciones.add( jp_ope, BorderLayout.CENTER );            
        this.cargaComboArea();
        //this.habilitarPestania(0); //No habilitamos pestanias
        this.tbp.setEnabledAt(0, false);
        this.tbp.setEnabledAt(1, false);
        jp_ma.setEnabled(false);
        jp_dc.setEnabled(false);
    }

    public JP_Utiles_PanelBotonesMantenimiento getJp_ope() {
        return jp_ope;
    }

    public void setJp_ope(JP_Utiles_PanelBotonesMantenimiento jp_ope) {
        this.jp_ope = jp_ope;
    }
    
    private void cargaComboArea(){        
        List listTbArea = null; // seteamos variable local
        List listaArea = comboBeanBindingArea1.getLista();
        listaArea.clear();
        try {
            listTbArea = GestionDelegate.getInstance().getListaArea();
        } catch (Exception e) {
            System.out.println( "Error en gestionDelegate.getListaArea()" );
            return;
        }
        this.comboBeanBindingArea1.setLista(listTbArea);
        this.bindingGroup.bind();
        this.cmbArea.updateUI();
        if( listTbArea.size() > 0 ){
            this.cmbArea.setSelectedIndex( 0 );
        }
    }

    private void cargaComboTipoAccion(){
        this.txtBusTipoAccion.setText( "" );
        if(this.rbtnCodigo.isSelected()){
            intelliHints = null;
        }else{
            List listTbTipoAccion = null;
            TbArea seleccionado;
            seleccionado = (TbArea) this.cmbArea.getSelectedItem();
            System.out.println( "Objeto seleccionado " + seleccionado.getCodArea() );
            try {
                listTbTipoAccion = GestionDelegate.getInstance().getTipoAccionNotificacionesByArea(seleccionado.getCodArea());
            } catch (Exception ex) {                
                System.out.println( "se produjo un error" );
                return;
            }
            intelliHints = new ListDataIntelliHints( this.txtBusTipoAccion, listTbTipoAccion );
            
        }       
    }

    private void buscarTipoAccion(){
        int codTipoAccion = -1;
        List listTbTipoAccion = null;
        TbArea seleccionado;
        seleccionado = (TbArea) this.cmbArea.getSelectedItem();
        System.out.println( "Objeto seleccionado " + seleccionado.getCodArea() );

        try {
            if( this.rbtnCodigo.isSelected() ){
                codTipoAccion = Integer.parseInt(this.txtBusTipoAccion.getText().trim());
            }else{
                TbTipoAccionClasificacionAccionArea tbTipoAccionClasificacionAccionArea = ( TbTipoAccionClasificacionAccionArea )this.intelliHints.getSelectedHint();
                codTipoAccion = tbTipoAccionClasificacionAccionArea.getTbTipoAccion().getCodTipoAccion().intValue();
            }
            listTbTipoAccion = GestionDelegate.getInstance().getTipoAccionByArea( seleccionado.getCodArea() , codTipoAccion );
        } catch (Exception ex) {
            //Logger.getLogger(JP_RegistrarAccion.class.getName()).log(Level.SEVERE, null, ex);
            System.out.println( "se produjo un error buscarTipoAccion  " + ex.getMessage() );
            return;
        }
        this.comboBeanBindingTbTipoAccionClasificacionAccionArea1.setLista(listTbTipoAccion);
        this.bindingGroup.bind();
        this.cmbClasificacion.updateUI();
        if( listTbTipoAccion.size() < 1 ){
                helper.Utiles_MensajesDialogo.mensajeError( "Codigo no existe" );
        }else{
            this.cmbClasificacion.setSelectedIndex(0); //ubicamos el primer elemnto de la lista
            Date fecha = new Date();
            helper.Utiles_Fecha uf = new helper.Utiles_Fecha(fecha);
            this.ftxtFechaRegistro.setText( uf.getFecha() );
            this.cmbClasificacion.requestFocus();
        }
    }
    
    public void inicializaReferencias(){
        jp_dc.setRef(getRef());
        jp_dc.setRefDep(this);
        jp_ma.setRef(getRef());
        jp_ma.setRefDep(this);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always re-generated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        comboBeanBindingTbTipoAccionClasificacionAccionArea1 = new beansbinding.ComboBeanBindingTbTipoAccionClasificacionAccionArea();
        comboBeanBindingArea1 = new beansbinding.ComboBeanBindingArea();
        buttonGroup1 = new javax.swing.ButtonGroup();
        jp_DocumentoIdentificacion = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        cmbArea = new javax.swing.JComboBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        atxtObservacion = new javax.swing.JTextArea();
        jPanel1 = new javax.swing.JPanel();
        txtBusTipoAccion = new javax.swing.JTextField();
        rbtnNombre = new javax.swing.JRadioButton();
        buttonGroup1.add( this.rbtnNombre );
        rbtnCodigo = new javax.swing.JRadioButton();
        buttonGroup1.add(this.rbtnCodigo);
        jLabel2 = new javax.swing.JLabel();
        cmbClasificacion = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        ftxtFechaRegistro = new javax.swing.JFormattedTextField();
        tbp = new javax.swing.JTabbedPane();
        jp_Masivo = new javax.swing.JPanel();
        jp_DatosCliente = new javax.swing.JPanel();
        jp_Operaciones = new javax.swing.JPanel();

        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(controlaccionescomercial.ControlAccionesComercialApp.class).getContext().getResourceMap(JP_RegistrarAccion1.class);
        jp_DocumentoIdentificacion.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("jp_DocumentoIdentificacion.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, resourceMap.getFont("jp_DocumentoIdentificacion.border.titleFont"))); // NOI18N
        jp_DocumentoIdentificacion.setName("jp_DocumentoIdentificacion"); // NOI18N

        jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel3.setFont(resourceMap.getFont("jLabel3.font")); // NOI18N
        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        cmbArea.setName("cmbArea"); // NOI18N

        org.jdesktop.beansbinding.ELProperty eLProperty = org.jdesktop.beansbinding.ELProperty.create("${lista}");
        org.jdesktop.swingbinding.JComboBoxBinding jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, comboBeanBindingArea1, eLProperty, cmbArea);
        bindingGroup.addBinding(jComboBoxBinding);

        cmbArea.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbAreaActionPerformed(evt);
            }
        });
        cmbArea.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                cmbAreaKeyPressed(evt);
            }
        });

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        atxtObservacion.setColumns(20);
        atxtObservacion.setRows(5);
        atxtObservacion.setName("atxtObservacion"); // NOI18N
        atxtObservacion.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                atxtObservacionKeyPressed(evt);
            }
        });
        jScrollPane1.setViewportView(atxtObservacion);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Tipo de Acción"));
        jPanel1.setName("jPanel1"); // NOI18N

        txtBusTipoAccion.setName("txtBusTipoAccion"); // NOI18N
        txtBusTipoAccion.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtBusTipoAccionKeyPressed(evt);
            }
        });

        rbtnNombre.setName("rbtnNombre"); // NOI18N
        rbtnNombre.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbtnNombreActionPerformed(evt);
            }
        });

        rbtnCodigo.setSelected(true);
        rbtnCodigo.setName("rbtnCodigo"); // NOI18N
        rbtnCodigo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbtnCodigoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(rbtnCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(rbtnNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(txtBusTipoAccion, javax.swing.GroupLayout.PREFERRED_SIZE, 562, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(41, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(rbtnCodigo)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(rbtnNombre))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(txtBusTipoAccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        cmbClasificacion.setName("cmbClasificacion"); // NOI18N

        eLProperty = org.jdesktop.beansbinding.ELProperty.create("${lista}");
        jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, comboBeanBindingTbTipoAccionClasificacionAccionArea1, eLProperty, cmbClasificacion);
        bindingGroup.addBinding(jComboBoxBinding);

        cmbClasificacion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbClasificacionActionPerformed(evt);
            }
        });
        cmbClasificacion.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                cmbClasificacionFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                cmbClasificacionFocusLost(evt);
            }
        });
        cmbClasificacion.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                cmbClasificacionKeyPressed(evt);
            }
        });

        jLabel4.setName("jLabel4"); // NOI18N

        ftxtFechaRegistro.setEnabled(false);
        ftxtFechaRegistro.setName("ftxtFechaRegistro"); // NOI18N

        javax.swing.GroupLayout jp_DocumentoIdentificacionLayout = new javax.swing.GroupLayout(jp_DocumentoIdentificacion);
        jp_DocumentoIdentificacion.setLayout(jp_DocumentoIdentificacionLayout);
        jp_DocumentoIdentificacionLayout.setHorizontalGroup(
            jp_DocumentoIdentificacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jp_DocumentoIdentificacionLayout.createSequentialGroup()
                .addGroup(jp_DocumentoIdentificacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jp_DocumentoIdentificacionLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jp_DocumentoIdentificacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4))
                        .addGroup(jp_DocumentoIdentificacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jp_DocumentoIdentificacionLayout.createSequentialGroup()
                                .addGap(26, 26, 26)
                                .addGroup(jp_DocumentoIdentificacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(cmbClasificacion, javax.swing.GroupLayout.Alignment.TRAILING, 0, 571, Short.MAX_VALUE)
                                    .addComponent(jScrollPane1)
                                    .addComponent(ftxtFechaRegistro, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(jp_DocumentoIdentificacionLayout.createSequentialGroup()
                                .addGap(27, 27, 27)
                                .addComponent(cmbArea, javax.swing.GroupLayout.PREFERRED_SIZE, 221, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 24, Short.MAX_VALUE)))
                .addGap(10, 10, 10))
        );
        jp_DocumentoIdentificacionLayout.setVerticalGroup(
            jp_DocumentoIdentificacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jp_DocumentoIdentificacionLayout.createSequentialGroup()
                .addGroup(jp_DocumentoIdentificacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(cmbArea, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jp_DocumentoIdentificacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cmbClasificacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addGap(6, 6, 6)
                .addGroup(jp_DocumentoIdentificacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ftxtFechaRegistro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addGap(10, 10, 10)
                .addGroup(jp_DocumentoIdentificacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jp_DocumentoIdentificacionLayout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(42, 42, 42))))
        );

        tbp.setName("tbp"); // NOI18N

        jp_Masivo.setName("jp_Masivo"); // NOI18N

        javax.swing.GroupLayout jp_MasivoLayout = new javax.swing.GroupLayout(jp_Masivo);
        jp_Masivo.setLayout(jp_MasivoLayout);
        jp_MasivoLayout.setHorizontalGroup(
            jp_MasivoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 707, Short.MAX_VALUE)
        );
        jp_MasivoLayout.setVerticalGroup(
            jp_MasivoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 178, Short.MAX_VALUE)
        );

        tbp.addTab(resourceMap.getString("jp_Masivo.TabConstraints.tabTitle"), jp_Masivo); // NOI18N

        jp_DatosCliente.setName("jp_DatosCliente"); // NOI18N

        javax.swing.GroupLayout jp_DatosClienteLayout = new javax.swing.GroupLayout(jp_DatosCliente);
        jp_DatosCliente.setLayout(jp_DatosClienteLayout);
        jp_DatosClienteLayout.setHorizontalGroup(
            jp_DatosClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 707, Short.MAX_VALUE)
        );
        jp_DatosClienteLayout.setVerticalGroup(
            jp_DatosClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 178, Short.MAX_VALUE)
        );

        tbp.addTab(resourceMap.getString("jp_DatosCliente.TabConstraints.tabTitle"), jp_DatosCliente); // NOI18N

        jp_Operaciones.setName("jp_Operaciones"); // NOI18N

        javax.swing.GroupLayout jp_OperacionesLayout = new javax.swing.GroupLayout(jp_Operaciones);
        jp_Operaciones.setLayout(jp_OperacionesLayout);
        jp_OperacionesLayout.setHorizontalGroup(
            jp_OperacionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 722, Short.MAX_VALUE)
        );
        jp_OperacionesLayout.setVerticalGroup(
            jp_OperacionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jp_Operaciones, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jp_DocumentoIdentificacion, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(tbp, javax.swing.GroupLayout.DEFAULT_SIZE, 712, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jp_DocumentoIdentificacion, javax.swing.GroupLayout.PREFERRED_SIZE, 256, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tbp, javax.swing.GroupLayout.PREFERRED_SIZE, 206, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(47, 47, 47)
                .addComponent(jp_Operaciones, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        bindingGroup.bind();
    }// </editor-fold>//GEN-END:initComponents

    private void cmbAreaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbAreaActionPerformed
        if( this.cmbArea.getSelectedItem() != null ){
            this.cargaComboTipoAccion();
        }
    }//GEN-LAST:event_cmbAreaActionPerformed

    private void rbtnCodigoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbtnCodigoActionPerformed
        cargaComboTipoAccion();
    }//GEN-LAST:event_rbtnCodigoActionPerformed

    private void rbtnNombreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbtnNombreActionPerformed
        cargaComboTipoAccion();
    }//GEN-LAST:event_rbtnNombreActionPerformed

    private void txtBusTipoAccionKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtBusTipoAccionKeyPressed
        if( evt.getKeyCode() == evt.VK_ENTER ){
            buscarTipoAccion();
        }
    }//GEN-LAST:event_txtBusTipoAccionKeyPressed

    private void cmbClasificacionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbClasificacionActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cmbClasificacionActionPerformed

    private void cmbClasificacionKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_cmbClasificacionKeyPressed
       if( evt.getKeyCode() == evt.VK_ENTER ){
            this.atxtObservacion.requestFocus();
        }
    }//GEN-LAST:event_cmbClasificacionKeyPressed

    private void cmbClasificacionFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_cmbClasificacionFocusGained
        // TODO add your handling code here:
    }//GEN-LAST:event_cmbClasificacionFocusGained

    private void cmbClasificacionFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_cmbClasificacionFocusLost
        try{
            TbTipoAccionClasificacionAccionArea tbTipoAccionClasificacionAccionArea = ( TbTipoAccionClasificacionAccionArea )this.cmbClasificacion.getSelectedItem();
            String codCatAccion = tbTipoAccionClasificacionAccionArea.getTbClasificacionAccion().getCodClasificacionAccion();
            if( codCatAccion.equalsIgnoreCase("GR") || codCatAccion.equalsIgnoreCase("M") ){
                this.tbp.setSelectedIndex(0);
                this.habilitarPestania(0);
            }else if( codCatAccion.equalsIgnoreCase("I") ){
                this.tbp.setSelectedIndex(1);
                this.habilitarPestania(1);
                int codTipoAccion = tbTipoAccionClasificacionAccionArea.getTbTipoAccion().getCodTipoAccion().intValue();
                System.out.println("codTipoAccion:"+codTipoAccion);
                if( codTipoAccion == 1116 || codTipoAccion == 3040 ){
                    this.jp_dc.getTxtNroInscripcion().setText("");
                    this.jp_dc.getTxtCodigoCatastral().setEnabled(false);
                    this.jp_dc.getTxtDireccion().setEnabled(true);
                    this.jp_dc.getTxtNombre().setEnabled(true);
                    this.jp_dc.getTxtNroInscripcion().setEnabled(false);
                    this.jp_dc.getTxtNroSolicitud().setEnabled(false);
                }else{
                    this.jp_dc.getTxtCodigoCatastral().setEnabled(false);
                    this.jp_dc.getTxtDireccion().setEnabled(false);
                    this.jp_dc.getTxtNombre().setEnabled(false);
                    this.jp_dc.getTxtNroInscripcion().setEnabled(true);
                    this.jp_dc.getTxtNroSolicitud().setEnabled(true);
                }
            }
           
        }catch( Exception e ){
        }
    }//GEN-LAST:event_cmbClasificacionFocusLost

    private void cmbAreaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_cmbAreaKeyPressed
        if( evt.getKeyCode() == evt.VK_ENTER ){
            this.txtBusTipoAccion.requestFocus();
        }
    }//GEN-LAST:event_cmbAreaKeyPressed

    private void atxtObservacionKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_atxtObservacionKeyPressed
        if( evt.getKeyCode() == evt.VK_ENTER ){
            if(tbp.getSelectedIndex() == 1){
               TbTipoAccionClasificacionAccionArea tbTipoAccionClasificacionAccionArea = ( TbTipoAccionClasificacionAccionArea )this.cmbClasificacion.getSelectedItem();
                int codTipoAccion = tbTipoAccionClasificacionAccionArea.getTbTipoAccion().getCodTipoAccion().intValue();
                System.out.println("codTipoAccion:"+codTipoAccion);
                if( codTipoAccion == 1116 || codTipoAccion == 3040 ){
                    jp_dc.getTxtNombre().requestFocus();
                }else{
                    jp_dc.getTxtNroInscripcion().requestFocus();
                }
                
            }else{
                jp_ma.getBtnImportar().requestFocus();
            }
        }
    }//GEN-LAST:event_atxtObservacionKeyPressed

    
    
    private void habilitarPestania( int index ){
        this.tbp.setEnabledAt(0, false);
        this.tbp.setEnabledAt(1, false);
        this.jp_ma.setEnabled(false);
        this.jp_dc.setEnabled(false);
        try {
            this.tbp.setEnabledAt(index, true);
            if( index == 0 ){
                this.jp_ma.setEnabled(true);
            }else if( index == 1 ){
                this.jp_dc.setEnabled(true);
            }
        } catch (Exception e) {
        }
    }   

    @Override
    public Task guardar() {
        return new Guarda(org.jdesktop.application.Application.getInstance(controlaccionescomercial.ControlAccionesComercialApp.class));        
    }
    
    private class Guarda extends org.jdesktop.application.Task<Object, Void> {
        Guarda(org.jdesktop.application.Application app) {
            super(app);
        }
        @Override protected Object doInBackground() {
            jp_ope.getBtnGuardar().setEnabled(false);
            ((JInternalFrame)getPadre()).setEnabled(false);
            guardarSegundoPlano();
            ((JInternalFrame)getPadre()).setEnabled(true);
            return null;  // return your result
        }
        @Override protected void succeeded(Object result) {
        }
    }

    public void guardarSegundoPlano(){
        try{
            //TbTipoAccionClasificacionAccionArea tbTipoAccionClasificacionAccionArea = ( TbTipoAccionClasificacionAccionArea )this.intelliHints.getSelectedHint();
            TbTipoAccionClasificacionAccionArea tbTipoAccionClasificacionAccionArea = ( TbTipoAccionClasificacionAccionArea )this.cmbClasificacion.getSelectedItem();
            String codCatAccion = tbTipoAccionClasificacionAccionArea.getTbClasificacionAccion().getCodClasificacionAccion();
            if( codCatAccion.equalsIgnoreCase("GR") ){
                this.guardarCorteReapertura();
            }else if(codCatAccion.equalsIgnoreCase("M") ){
                this.guardarMasivo();
            }else if( codCatAccion.equalsIgnoreCase("I") ){
                this.guardarIndividual();
            }
            limpiarRegistro();
        }catch( Exception ex ){
            ex.printStackTrace();
            jp_ope.getBtnGuardar().setEnabled(true);
            Utiles_MensajesDialogo.mensajeError("Error al realizar la operación");
        }
    }

    public void limpiarRegistro(){
        this.jp_ope.getBtnGuardar().setEnabled(true);
        this.jp_dc.limpiar();
        this.jp_ma.limpiarLista();
        this.atxtObservacion.setText("");
        this.cmbArea.setSelectedIndex(0);
        this.txtBusTipoAccion.setText("");
        this.cmbClasificacion.setSelectedIndex( -1 );
        this.ftxtFechaRegistro.setText( "" );
        this.cmbArea.requestFocus();
        this.tbp.setEnabledAt(0,false);
        this.tbp.setEnabledAt(1,false);
        this.tbp.setEnabled(false);
    }

    @Override
    public Task limpiar() {
        limpiarRegistro();
        //this.cmbTipoAccion.setSelectedIndex(-1);
        return null;
    }
    
    @Override
    public Task cerrar() {
        this.cerrarPadre();
        return null;
    }

    //Metodos para guardar
    private void guardarCorteReapertura() throws Exception{
        listaClientes = this.jp_ma.getListaClientes();
        TbTipoAccionClasificacionAccionArea tipoAccion = null;
        try {
            //tipoAccion = (TbTipoAccionClasificacionAccionArea) this.intelliHints.getSelectedHint();
            tipoAccion = (TbTipoAccionClasificacionAccionArea) this.cmbClasificacion.getSelectedItem();
        } catch (Exception e) {
            Utiles_MensajesDialogo.mensajeAlerta("Debe seleccionar un item del combo Tipo de Accion");
            return;
        }
        String atexto = this.atxtObservacion.getText().trim();
        GestionDelegate.getInstance().registraAccionCorteReapertura(listaClientes, tipoAccion, atexto , ControlAccionesComercialApp.LOG_USER);
    }

    private void guardarMasivo() throws Exception{
        listaClientes = this.jp_ma.getListaClientes();
        String atexto = this.atxtObservacion.getText().trim();
        //GestionDelegate.getInstance().registraAccionMasiva(listaClientes,(TbTipoAccionClasificacionAccionArea) this.intelliHints.getSelectedHint(), atexto);
        GestionDelegate.getInstance().registraAccionMasiva(listaClientes,(TbTipoAccionClasificacionAccionArea) this.cmbClasificacion.getSelectedItem(), atexto,ControlAccionesComercialApp.LOG_USER);
    }

    private void guardarIndividual() throws Exception{
        tbCliente = new TbCliente();
        String num_inscrip = this.jp_dc.getTxtNroInscripcion().getText().trim();
        String nroSolicitud = this.jp_dc.getTxtNroSolicitud().getText().trim();
        String nombre = this.jp_dc.getTxtNombre().getText().trim();
        String direccion = this.jp_dc.getTxtDireccion().getText().trim();
        String atexto = this.atxtObservacion.getText().trim();

        if( nombre.trim().equals("") || direccion.trim().equals("") ){
            helper.Utiles_MensajesDialogo.mensajeError( "Nombre o dirección inválidos" );
        }else{
            tbCliente.setNumInscrip( num_inscrip );
            tbCliente.setNroSolicitud(nroSolicitud);
            tbCliente.setNombre(nombre);
            tbCliente.setDireccion(direccion);
            GestionDelegate.getInstance().registraAccionIndividual(tbCliente,(TbTipoAccionClasificacionAccionArea) this.cmbClasificacion.getSelectedItem(), atexto,ControlAccionesComercialApp.LOG_USER);
        }
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextArea atxtObservacion;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JComboBox cmbArea;
    private javax.swing.JComboBox cmbClasificacion;
    private beansbinding.ComboBeanBindingArea comboBeanBindingArea1;
    private beansbinding.ComboBeanBindingTbTipoAccionClasificacionAccionArea comboBeanBindingTbTipoAccionClasificacionAccionArea1;
    private javax.swing.JFormattedTextField ftxtFechaRegistro;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel jp_DatosCliente;
    private javax.swing.JPanel jp_DocumentoIdentificacion;
    private javax.swing.JPanel jp_Masivo;
    private javax.swing.JPanel jp_Operaciones;
    private javax.swing.JRadioButton rbtnCodigo;
    private javax.swing.JRadioButton rbtnNombre;
    private javax.swing.JTabbedPane tbp;
    private javax.swing.JTextField txtBusTipoAccion;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables
    private JP_Utiles_PanelBotonesMantenimiento jp_ope;
    private JP_DatosCliente jp_dc;
    private JP_Masivo jp_ma;

    //Datos los cuales van a realizar la persistencia del objeto
    private List<TbCliente> listaClientes;
    private TbCliente tbCliente;
    private ListDataIntelliHints intelliHints;
}
